package com.ymatou.iapi.liveseller.testcase;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.liveseller.parameter.ActivityProductDto;
import com.ymatou.iapi.liveseller.parameter.CreateLiveActivityBean;
import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymatou.iapi.liveseller.parameter.ModifyLiveActivityBean;
import com.ymatou.iapi.liveseller.service.ModifyLiveActivityCall;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CounterCallService;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.database.model.LiveActivity;
import com.ymttest.database.model.LiveActivityProduct;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.RunTests;
import com.ymttest.utils.YMTDateUtil;
/**
*修改直播活动
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ModifyLiveActivity{
	private static ModifyLiveActivityBean modifyliveactivityBean;
	private static ModifyLiveActivityCall modifyliveactivityCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("修改直播活动");
	}

	@Before
	public void caseUp() {
		modifyliveactivityBean=new ModifyLiveActivityBean();
		modifyliveactivityCall=new ModifyLiveActivityCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(modifyliveactivityCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void verifyDB(ModifyLiveActivityBean liveactivityBean2) throws InterruptedException {
		LiveRoomWapper LiveRoomWapper = new LiveRoomWapper();
		Integer liveacctivityid = liveactivityBean2.getLiveActivity().getLiveActivityId();
		LiveActivity activity = LiveRoomWapper.selectLiveactivityById(liveacctivityid);
		Logger.verifyEquals(0, activity.getActivityState(), "验证ActivityState");
		// 通知由job决定 发送过了为1
		Logger.verifyNotNull(activity.getBuyerNotify(), "验证BuyerNotify");
		Logger.verifyNotNull(activity.getSellerNotify(), "验证SellerNotify");

		Logger.verifyNotNull(activity.getCreateTime(), "验证CreateTime");
		Logger.verifyEquals(liveactivityBean2.getLiveActivity().getSellerId(), activity.getSellerId(), "验证SellerId");
		// 可能有误差
		Logger.verifyEquals(Long.valueOf(liveactivityBean2.getLiveActivity().getStartTime()) / 10000, activity.getStartTime().getTime() / 10000, "验证StartTime");
		Logger.verifyEquals(Long.valueOf(liveactivityBean2.getLiveActivity().getEndTime()) / 10000, activity.getEndTime().getTime() / 10000, "验证EndTime");
		Integer stock = liveactivityBean2.getLiveActivity().getActivityProducts().stream().collect(Collectors.summingInt(ActivityProductDto::getActivityStock));
		liveactivityBean2.getLiveActivity().getActivityProducts().forEach(ap -> {
			try {
				LiveActivityProduct aproduct = LiveRoomWapper.selectLiveactivityproduct(liveacctivityid, ap.getProductId()).get(0);

				Logger.verifyEquals(liveactivityBean2.getLiveActivity().getLiveId(), aproduct.getLiveId(), "验证liveid");
				Logger.verifyEquals(liveactivityBean2.getLiveActivity().getSellerId(), aproduct.getSellerId(), "验证SellerId");
				Logger.verifyEquals(stock, aproduct.getActivityStock(), "验证ActivityStock");
				//规格库存和价格要在库存服务维护
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});

	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifyLiveActivity_001() {
		Logger.start(true,"修改直播活动,成功");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			
			modifyliveactivityBean=LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			//修改结束时间
			modifyliveactivityBean.getLiveActivity().setEndTime(String.valueOf(new Date(now.getTime() + 201 * 60 * 1000).getTime()));
			//修改价格和库存
			modifyliveactivityBean.getLiveActivity().getActivityProducts().forEach(ap->{
				ap.setActivityStock(ap.getActivityStock()-1);
				ap.setActivityPrice(ap.getActivityPrice()-1);
			});
			modifyliveactivityCall.setData(modifyliveactivityBean);
			modifyliveactivityCall.callService();			
			Logger.verifyEquals("200", modifyliveactivityCall.getString("Code"), "验证成功");
			verifyDB(modifyliveactivityBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ModifyLiveActivity_002() {
		Logger.start(true,"不传参数LiveActivity失败");
		try {
			modifyliveactivityCall.setData(modifyliveactivityBean);
			modifyliveactivityCall.callService();			
			Logger.verifyEquals("500", modifyliveactivityCall.getString("Code"), "验证成功");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifyLiveActivity_003() {
		Logger.start(true,"修改直播活动,成功,多规格");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			List<ActivityProductDto> ActivityProducts = new ArrayList<>();
			for (int i = 0; i < 2; i++) {
				ActivityProductDto apd = new ActivityProductDto();
				apd.setActivityPrice(5.0d);
				apd.setActivityStock(10);
				apd.setCatalogId(cids.get(i));
				apd.setProductId(productId);
				ActivityProducts.add(apd);
			}
			createliveactivityBean.getLiveActivity().setActivityProducts(ActivityProducts);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			
			modifyliveactivityBean=LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			//修改结束时间
			modifyliveactivityBean.getLiveActivity().setEndTime(String.valueOf(new Date(now.getTime() + 201 * 60 * 1000).getTime()));
			//修改价格和库存
			modifyliveactivityBean.getLiveActivity().getActivityProducts().forEach(ap->{
				ap.setActivityStock(ap.getActivityStock()-1);
				ap.setActivityPrice(ap.getActivityPrice()-1);
			});
			modifyliveactivityCall.setData(modifyliveactivityBean);
			modifyliveactivityCall.callService();			
			Logger.verifyEquals("200", modifyliveactivityCall.getString("Code"), "验证成功");
			verifyDB(modifyliveactivityBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
//	#直播活动最多添加商品数 配置决定
//	liveActivityProductCount=10
	public void Tc_ModifyLiveActivity_004() {
		Logger.start(true,"一场秒杀最多只支持1个商品");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			AddSellerProductRequest addpro2 = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId2 = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			List<String> cids2 = CIWapper.selectCatalogsByProductId(productId2).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			
			modifyliveactivityBean=LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			//修改结束时间
			modifyliveactivityBean.getLiveActivity().setEndTime(String.valueOf(new Date(now.getTime() + 201 * 60 * 1000).getTime()));
			//修改价格和库存
			modifyliveactivityBean.getLiveActivity().getActivityProducts().forEach(ap->{
				ap.setActivityStock(ap.getActivityStock()-1);
				ap.setActivityPrice(ap.getActivityPrice()-1);
			});
			ActivityProductDto otherp=new ActivityProductDto();
			otherp.setProductId(productId2);
			otherp.setCatalogId(cids2.get(0));
			otherp.setActivityStock(1);
			otherp.setActivityPrice(1d);
			otherp.setActivityProductId(modifyliveactivityBean.getLiveActivity().getActivityProducts().get(0).getActivityProductId());
			modifyliveactivityBean.getLiveActivity().getActivityProducts().add(otherp);
			modifyliveactivityCall.setData(modifyliveactivityBean);
			modifyliveactivityCall.callService();			
			Logger.verifyEquals("201", modifyliveactivityCall.getString("Code"), "验证失败");
			// 一场秒杀最多只支持1个商品
			Logger.verifyIsContains("一场秒杀最多只支持1个商品", modifyliveactivityCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifyLiveActivity_005() {
		Logger.start(true,"直播已关闭");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			LiveRoomCallService.AutoCloseLiveRoomByUserId(sellerId);
			modifyliveactivityBean=LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			//修改结束时间
			modifyliveactivityBean.getLiveActivity().setEndTime(String.valueOf(new Date(now.getTime() + 201 * 60 * 1000).getTime()));
			//修改价格和库存
			modifyliveactivityBean.getLiveActivity().getActivityProducts().forEach(ap->{
				ap.setActivityStock(ap.getActivityStock()-1);
				ap.setActivityPrice(ap.getActivityPrice()-1);
			});
			modifyliveactivityCall.setData(modifyliveactivityBean);
			modifyliveactivityCall.callService();			
			Logger.verifyEquals("201", modifyliveactivityCall.getString("Code"), "验证成功");
			Logger.verifyIsContains("直播已关闭", modifyliveactivityCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifyLiveActivity_006() {
		Logger.start(true,"秒杀时间不可早于直播开始时间");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			
			modifyliveactivityBean=LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			//秒杀时间不可早于直播开始时间
			modifyliveactivityBean.getLiveActivity().setStartTime(String.valueOf(starttime.getTime()-1 * 60 * 1000));
			//修改结束时间
			modifyliveactivityBean.getLiveActivity().setEndTime(String.valueOf(new Date(now.getTime() + 201 * 60 * 1000).getTime()));
			//修改价格和库存
			modifyliveactivityBean.getLiveActivity().getActivityProducts().forEach(ap->{
				ap.setActivityStock(ap.getActivityStock()-1);
				ap.setActivityPrice(ap.getActivityPrice()-1);
			});
			modifyliveactivityCall.setData(modifyliveactivityBean);
			modifyliveactivityCall.callService();			
			Logger.verifyEquals("201", modifyliveactivityCall.getString("Code"), "验证成功");
			Logger.verifyIsContains("秒杀时间不可早于直播开始时间", modifyliveactivityCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	//此场景现在取消判断 20181220 @陈飞
	public void Tc_ModifyLiveActivity_007() {
		Logger.start(true,"秒杀时间不可晚于直播结束时间");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			
			modifyliveactivityBean=LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			//秒杀时间不可早于直播开始时间
			modifyliveactivityBean.getLiveActivity().setStartTime(String.valueOf(endtime.getTime()+1 * 60 * 1000));
			//修改结束时间
			modifyliveactivityBean.getLiveActivity().setEndTime(String.valueOf(endtime.getTime()+10 * 60 * 1000));
			//修改价格和库存
			modifyliveactivityBean.getLiveActivity().getActivityProducts().forEach(ap->{
				ap.setActivityStock(ap.getActivityStock()-1);
				ap.setActivityPrice(ap.getActivityPrice()-1);
			});
			modifyliveactivityCall.setData(modifyliveactivityBean);
			modifyliveactivityCall.callService();			
			Logger.verifyEquals("201", modifyliveactivityCall.getString("Code"), "验证成功");
			Logger.verifyIsContains("秒杀时间不可晚于直播结束时间", modifyliveactivityCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifyLiveActivity_008() {
		Logger.start(true,"秒杀活动必须设置至少一个商品");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			modifyliveactivityBean=LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			//修改结束时间
			modifyliveactivityBean.getLiveActivity().setEndTime(String.valueOf(new Date(now.getTime() + 201 * 60 * 1000).getTime()));
			//修改价格和库存
			modifyliveactivityBean.getLiveActivity().getActivityProducts().remove(0);
			modifyliveactivityCall.setData(modifyliveactivityBean);
			modifyliveactivityCall.callService();			
			Logger.verifyEquals("400", modifyliveactivityCall.getString("Code"), "验证成功");
			Logger.verifyIsContains("不能为空", modifyliveactivityCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifyLiveActivity_009() {
		Logger.start(true,"开始时间与其他秒杀冲突");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			//在这里注意顺序
			modifyliveactivityBean=LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			
			Logger.comment("创建秒杀活动2");
			CreateLiveActivityBean createliveactivityBean2 = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, new Date(Long.valueOf(createliveactivityBean.getLiveActivity().getEndTime())+1000));
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean2);
			
			//修改开始时时间
			modifyliveactivityBean.getLiveActivity().setStartTime(createliveactivityBean2.getLiveActivity().getStartTime());
			//修改结束时间
			modifyliveactivityBean.getLiveActivity().setEndTime(createliveactivityBean2.getLiveActivity().getEndTime());
			//修改价格和库存
			modifyliveactivityBean.getLiveActivity().getActivityProducts().forEach(ap->{
				ap.setActivityStock(ap.getActivityStock()-1);
				ap.setActivityPrice(ap.getActivityPrice()-1);
			});
			modifyliveactivityCall.setData(modifyliveactivityBean);
			modifyliveactivityCall.callService();			
			Logger.verifyEquals("201", modifyliveactivityCall.getString("Code"), "验证成功");
			Logger.verifyIsContains("开始时间与其他秒杀冲突", modifyliveactivityCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifyLiveActivity_010() {
		Logger.start(true,"规格不存在");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			
			modifyliveactivityBean=LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			//修改结束时间
			modifyliveactivityBean.getLiveActivity().setEndTime(String.valueOf(new Date(now.getTime() + 201 * 60 * 1000).getTime()));
			//修改价格和库存
			modifyliveactivityBean.getLiveActivity().getActivityProducts().forEach(ap->{
				ap.setCatalogId("notexist");
				ap.setActivityStock(ap.getActivityStock()-1);
				ap.setActivityPrice(ap.getActivityPrice()-1);
			});
			modifyliveactivityCall.setData(modifyliveactivityBean);
			modifyliveactivityCall.callService();			
			Logger.verifyEquals("201", modifyliveactivityCall.getString("Code"), "验证成功");
			Logger.verifyIsContains("规格不存在", modifyliveactivityCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifyLiveActivity_011() {
		Logger.start(true,"秒杀价不得高于当前售价");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			
			modifyliveactivityBean=LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			//修改结束时间
			modifyliveactivityBean.getLiveActivity().setEndTime(String.valueOf(new Date(now.getTime() + 201 * 60 * 1000).getTime()));
			//修改价格和库存
			modifyliveactivityBean.getLiveActivity().getActivityProducts().forEach(ap->{
				ap.setActivityStock(ap.getActivityStock()-1);
				ap.setActivityPrice(100d);
			});
			modifyliveactivityCall.setData(modifyliveactivityBean);
			modifyliveactivityCall.callService();			
			Logger.verifyEquals("201", modifyliveactivityCall.getString("Code"), "验证成功");
			Logger.verifyIsContains("秒杀价不得高于当前售价", modifyliveactivityCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifyLiveActivity_012() {
		//这里逻辑有问题 修改的时候如果修改库存小于已有活动库存,用的是返库存逻辑
		Logger.start(true,"秒商品规格库存已售罄");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			CIWapper.updatestocknumByProductID(0, productId);
			modifyliveactivityBean=LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			//修改结束时间
			modifyliveactivityBean.getLiveActivity().setEndTime(String.valueOf(new Date(now.getTime() + 201 * 60 * 1000).getTime()));
			//修改价格和库存
			modifyliveactivityBean.getLiveActivity().getActivityProducts().forEach(ap->{
				ap.setActivityStock(ap.getActivityStock()+1);
				ap.setActivityPrice(1d);
			});
			modifyliveactivityCall.setData(modifyliveactivityBean);
			modifyliveactivityCall.callService();			
			Logger.verifyEquals("201", modifyliveactivityCall.getString("Code"), "验证成功");
			Logger.verifyIsContains("失败", modifyliveactivityCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifyLiveActivity_013() {
		Logger.start(true,"活动库存超出最大库存");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			CIWapper.updatestocknumByProductID(10, productId);
			modifyliveactivityBean=LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			//修改结束时间
			modifyliveactivityBean.getLiveActivity().setEndTime(String.valueOf(new Date(now.getTime() + 201 * 60 * 1000).getTime()));
			//修改价格和库存
			modifyliveactivityBean.getLiveActivity().getActivityProducts().forEach(ap->{
				ap.setActivityStock(2000);
				ap.setActivityPrice(1d);
			});
			modifyliveactivityCall.setData(modifyliveactivityBean);
			modifyliveactivityCall.callService();			
			Logger.verifyEquals("201", modifyliveactivityCall.getString("Code"), "验证成功");
			Logger.verifyIsContains("失败", modifyliveactivityCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	//参加直播秒杀的商品禁止报名活动 无法具备前置条件
	public void Tc_ModifyLiveActivity_014() {
		Logger.start(true,"有其他交易隔离活动冲突失败有其他交易隔离活动冲突失败");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			
			Logger.comment("创建交易隔离活动");
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,cids,activityId, 100,"10");
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);
			
			modifyliveactivityBean=LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			//修改结束时间
			modifyliveactivityBean.getLiveActivity().setEndTime(String.valueOf(new Date(now.getTime() + 201 * 60 * 1000).getTime()));
			//修改价格和库存
			modifyliveactivityBean.getLiveActivity().getActivityProducts().forEach(ap->{
				ap.setActivityStock(ap.getActivityStock()-1);
				ap.setActivityPrice(ap.getActivityPrice()-1);
			});
			modifyliveactivityCall.setData(modifyliveactivityBean);
			modifyliveactivityCall.callService();			
			Logger.verifyEquals("201", modifyliveactivityCall.getString("Code"), "验证成功");
			Logger.verifyIsContains("该活动商品无法加入秒杀", modifyliveactivityCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifyLiveActivity_015() {
		//这里逻辑有问题 修改的时候如果修改库存小于已有活动库存,用的是返库存逻辑
		Logger.start(true,"秒商品规格库存已售罄,修改库存小于第一次活动申请库存,成功");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			CIWapper.updatestocknumByProductID(0, productId);
			modifyliveactivityBean=LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			//修改结束时间
			modifyliveactivityBean.getLiveActivity().setEndTime(String.valueOf(new Date(now.getTime() + 201 * 60 * 1000).getTime()));
			//修改价格和库存
			modifyliveactivityBean.getLiveActivity().getActivityProducts().forEach(ap->{
				ap.setActivityStock(ap.getActivityStock()-1);
				ap.setActivityPrice(1d);
			});
			modifyliveactivityCall.setData(modifyliveactivityBean);
			modifyliveactivityCall.callService();			
			Logger.verifyEquals("200", modifyliveactivityCall.getString("Code"), "验证成功");
			verifyDB(modifyliveactivityBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ModifyLiveActivity_016() {
		Logger.start(true,"修改直播活动,成功、发送一条计数器");
		try {
			Logger.comment("创建商品");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("创建直播");
			// 5分钟后开始200分钟后结束
			CreateSellerLiveBean clive = LiveRoomCallService.initCreatesellerliveBean(sellerId);
			Date now = YMTDateUtil.getDate();
			//半小时之内会锁定不能修改
			Date starttime = new Date(now.getTime() + 60 * 60 * 1000);
			Date endtime = new Date(now.getTime() + 200 * 60 * 1000);
			clive.getLiveDto().setStartTime(YMTDateUtil.getFormatTime(starttime, YMTDateUtil.YMDHMS));
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(clive);
			Logger.comment("加入商品");
			LiveRoomCallService.AddProductsToLive(createlive.getId(), sellerId, productId);
			Logger.comment("查询商品规格");
			YmtCatalogsIWapper CIWapper = new YmtCatalogsIWapper();
			List<String> cids = CIWapper.selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			Logger.comment("创建秒杀活动");
			CreateLiveActivityBean createliveactivityBean = LiveRoomCallService.initCreateLiveActivityBean(createlive.getId(), cids.get(0), 5d, 6, starttime);
			LiveRoomCallService.CreateLiveActivity(createliveactivityBean);
			
			modifyliveactivityBean=LiveRoomCallService.initModifyLiveActivityBean(createliveactivityBean);
			//修改结束时间
			modifyliveactivityBean.getLiveActivity().setEndTime(String.valueOf(new Date(now.getTime() + 201 * 60 * 1000).getTime()));
			//修改价格和库存
			modifyliveactivityBean.getLiveActivity().getActivityProducts().forEach(ap->{
				ap.setActivityStock(ap.getActivityStock()-1);
				ap.setActivityPrice(ap.getActivityPrice()-1);
			});
			modifyliveactivityCall.setData(modifyliveactivityBean);
			Integer counter = CounterCallService.getSingleValueByLiveId(createlive.getId());
			modifyliveactivityCall.callService();			
			Logger.verifyEquals("200", modifyliveactivityCall.getString("Code"), "验证成功");
			
			Integer counter1 = CounterCallService.getSingleValueByLiveId(createlive.getId());
			Logger.verifyEquals(counter+2, counter1, "添加商品之后，计数器+1");
			
			verifyDB(modifyliveactivityBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
}